#include <iostream>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;	

int stk[N], top;

int a[N], b[N];

void init()
{
	top = 0;
	memset(stk, 0, sizeof stk);
}
int main()
{
	int T;
	cin >> T;

	while (T -- )
	{
		int n;
		cin >> n;
		top = 0;
		
		for (int i = 0; i < n; i ++ ) cin >> a[i];
		for (int i = 0; i < n; i ++ ) cin >> b[i];
		
		for (int i = 0, j = 0; i < n; i ++ )
		{
			stk[ ++ top] = a[i];
			while (j < n && stk[top] == b[j])
			{
				j ++ ;
				top -- ;
			}
		}
		
		if (top == 0) puts("Yes");
		else puts("No");
	}
	
	return 0;
}